package com.kgc.scd.controller;

import com.kgc.scd.service.CouponService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.vo.NideshopCollectVO;
import com.kgc.scd.vo.ShopUserCouponVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created On : 2022/11/15.
 * <p>
 * Author : yantao
 * <p>
 * Description: CouponServerController
 */
@Slf4j
@RestController
@RequestMapping("/ytserver")
public class CouponServerController {
    @Autowired
    private CouponService couponService;

    /**
     * @author : yantao
     * @date   : 2022/11/15
     * @param  : [pageNo, pageSize, name, userId]
     * @return : com.kgc.scd.util.PageSupport<com.kgc.scd.vo.NideshopCollectVO>
     * @description : 领取优惠券
     */
    @GetMapping("getCoupons")
    public String getCoupons(@RequestParam String couponId,

                             @RequestParam String userId){

        log.info("++++++ getCoupons server端接收信息:优惠卷:{},用户:{}",couponId,userId);
        return couponService.addCouponsUser(couponId, userId);


    }


    /**
     * @author : yantao
     * @date   : 2022/11/16
     * @param  : [userCouponId, categoryId, money, userId]
     * @return : java.util.Map<java.lang.String,java.lang.Object>
     * @description : 消费优惠券
     */
    @GetMapping("/judgeCoupons")
    public Map<String, Object> judgeCoupons(@RequestParam String userCouponId,
                                            @RequestParam String categoryId,
                                            @RequestParam Double money,
                                            @RequestParam String userId){

        return couponService.examineCouponsState(userCouponId, categoryId, money,userId);
    }


    /**
     * @author : yantao
     * @date   : 2022/11/16
     * @param  : [userCouponId]
     * @return : boolean
     * @description : 删除优惠券
     */
    @GetMapping("/delectCouponServer")
    public boolean  delectCouponServer(@RequestParam String userCouponId){
        return couponService.deleteUserCoupon(userCouponId);
    }

    /**
     * @author : yantao
     * @date   : 2022/11/16
     * @param  : [userId]
     * @return : java.util.List<com.kgc.scd.vo.ShopUserCouponVO>
     * @description : 查询使用的用户优惠券
     */
    @GetMapping("/getCouponsAll")
    public List<ShopUserCouponVO> getCouponsAll(@RequestParam String userId){
        return couponService.selectUserCouponAll(userId);
    }

    /**
     * @author : yantao
     * @date   : 2022/11/18
     * @param  : [userCouponId]
     * @return : void
     * @description : 用户使用积分
     */
    @GetMapping("userUseCoupon")
    public void userUseCoupon(@RequestParam String userCouponId){
        couponService.useCoupon(userCouponId);
    }
}
